Learn how to use an API client or the dashboard to create conditionless, always active Rules.
The most common use case for Rules is to alter search results depending on a particular condition. However, you can also create Rules that are active for all searches in the Rule’s associated index.This guide shows you how to create a conditionless Rule, but doesn’t specify the consequences.Possible consequences include:
To create a Rule with an API client, use the saveRule method on a Rule object without a condition.
Copy
Ask AI
Rule ruleToSave = new Rule{ ObjectID = "a-rule-id", Consequence = new Consequence { // Set relevant consequence(s) }, { new TimeRange // Set validity (optional) { From = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(), Until = new DateTimeOffset(DateTime.UtcNow.AddDays(30)).ToUnixTimeSeconds() } }};index.SaveRule(rule);// Asynchronousawait index.SaveRuleAsync(rule);
Select the Rules section from the left sidebar menu in the Algolia dashboard.
Under the heading Rules, select the index you are adding a Rule to.
Select Create your first rule or New rule. In the dropdown, click on the Manual Editor option. You can’t create conditionless Rules using the Visual Editor.
In the Condition(s) section, click the Remove button with the trash can icon at the top right of the condition.
In the Consequence(s) section, set the relevant consequence(s).
If this rule is only applicable for a certain period of time, select the time range in the Additional Settings, under the Timeframe in UTC header.
If you want to forward the Rule to replicas or other indices, toggle Copy this rule to other indices, and enter the relevant indices.